--[[/**
-- * 
 * 阿莉克希亚 大招 平均回复
-- */]]

---@class BuffEffect392101 : BaseBuffEffect
BuffEffect392101 = ClientFight.CreateClass("BuffEffect392101", ClientFight.BaseBuffEffect)
local t = BuffEffect392101

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    if (isDamageActionTrigger(buff)) then
        local isBuff = parameters[4];
        if (isBuff) then
            return IBuffEffect.FAIL;
        end
    end
    local source = buff.source;
    local calculateAttrType = buff.buffBean.f_BuffEffectValue[1];
    local modifiedRatio = buff.buffBean.f_BuffEffectValue[2];
    local peopleAmount = source.parametersByObject[BuffEffect392100.BUFF_EFFECT_392100_FIGHTER_AMOUNT] or 0;
    if (peopleAmount <= 0) then
        return IBuffEffect.REMOVE;
    end
    local result = FightResult.New();
    result.state = DamageResultTypeEnum.HEAL;
    result.damage = AttackUtils.calculateEffectHeal(buff, source, calculateAttrType, modifiedRatio / peopleAmount, 0);
    local beforHp = buff.target.hp;
    DamageManager.realDamage(fight, buff.source, buff.target, buff.modelId, result, SkillDamageTypeEnum.HEAL);
    SkillRoleMgr.savePathFile(string.format("[%s][EFFECT]Fighter %s  Buff%s 大招平均回复,有%s人,回复效果%s",
            fight.frame, buff.target.fighterId, buff.modelId, peopleAmount, modifiedRatio / peopleAmount
    ));
    local overlap = source.parametersByObject[BuffEffect398100.BUFF_EFFECT_398100_OVERLAP] or 0;
    if (overlap > 0) then
        local overHp = beforHp + result.damage - FighterAttributeManager.getFightAttr(buff.target, FighterAttributeEnum.HP);
        local addHp = (long)(overHp * Utils.toRatio(overlap));
        if (addHp >= 1) then
            --超出部分 奶自己一口
            SkillRoleMgr.savePathFile(string.format("[%s][EFFECT]Fighter %s  Buff%s 大招治疗溢出,奶自己一口:%s",
                    fight.frame, buff.target.fighterId, buff.modelId, addHp));
            DamageManager.setFighterHp(fight, buff.source, buff.source, nil, DamageResultTypeEnum.HEAL, addHp, buff.source.hp + addHp, true, false, true);
        end
    end
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

t.New()